package com.blockchain.securewallet.dialog;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.blockchain.securewallet.R;
import com.blockchain.securewallet.WalletApp;

public class CommonDialog extends DialogFragment {

    public static final int TYPE_SINGLE_INPUT = 1;

    public static final String KEY_TITLE = "title";
    public static final String KEY_TYPE = "type";
    public static final String KEY_HINT_TEXT = "hint";


    private int type = -1;
    private int titleResId;
    private int hintTextResId;


    private EditText editText;
    private TextView tvTitle;

    public static void showReceiveCoinSetDialog(FragmentManager fm) {
        CommonDialog dialog = CommonDialog.newInstance(TYPE_SINGLE_INPUT,R.string.receive_coin,R.string.receive_coin_hint);
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(dialog,"dialog_single_input");
        ft.commit();
    }

    public static CommonDialog newInstance(int type,int title,int hintTextResId){
        CommonDialog dialog = new CommonDialog();
        Bundle args = new Bundle();
        args.putInt(KEY_TITLE,title);
        args.putInt(KEY_HINT_TEXT,hintTextResId);
        args.putInt(KEY_TYPE,type);
        dialog.setArguments(args);
        return dialog;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (type == TYPE_SINGLE_INPUT) {
            return inflater.inflate(R.layout.dialog_single_input,container);
        }else {
            return super.onCreateView(inflater, container, savedInstanceState);
        }
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        editText = (EditText)view.findViewById(R.id.edit_text);
        tvTitle = (TextView)view.findViewById(R.id.tv_title);
        editText.setHint(hintTextResId);
        tvTitle.setText(titleResId);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        type = getArguments().getInt(KEY_TYPE);
        titleResId = getArguments().getInt(KEY_TITLE);
        hintTextResId = getArguments().getInt(KEY_HINT_TEXT);
    }

    interface OnClickListener {
        void onClick(int pos);
    }
}
